using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TerritoryGame.Domain.Repositories;
using TerritoryGame.Infrastructure.Data;
using TerritoryGame.Infrastructure.Repositories;

namespace TerritoryGame.Infrastructure;

public static class ServicesConllectionExtensition
{
    public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
    {
        // 添加数据库上下文
        services.AddDbContext<TerritoryGameDbContext>(options =>
            options.UseNpgsql(configuration.GetConnectionString("DefaultConnection")));

        // 添加Redis服务
        services.AddSingleton<IRedisService, RedisService>();

        // 添加仓储
        services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));

        return services;
    }
}